package com.lx.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lx.entities.Result;
import com.lx.entities.User;
import com.lx.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService uservice;
	
	/**
	 * 展示列表
	 * @return
	 */
	@RequestMapping("/find")
	@ResponseBody
	public List<User> findUsers(){
		return uservice.findUsers();
	}
	
	/**
	 * 保存用户
	 * @param u
	 * @return
	 */
	@RequestMapping("/save")
	@ResponseBody
	public Result saveUser(User u){ 
		int res = uservice.save(u);
		return new Result(res);
	}
	
	/**
	 * 批量删除用户
	 * @param ids
	 * @return
	 */
	@RequestMapping("/del/{ids}")
	@ResponseBody
	public Result delUsers(@PathVariable("ids") String ids){
		int res = uservice.delUsers(ids);
		return new Result(res);
	}
	
	/**
	 * 根据ID查询用户
	 * @param uid
	 * @return
	 */
	@RequestMapping("/findById/{uid}")
	@ResponseBody
	public User findById(@PathVariable("uid") Integer uid){
		return uservice.findUserById(uid);
	}
}
